<#include "common.ftl">
ALTER TABLE ${tableName}
<#list fieldPOList as field>
<#--修改列名或新增列-->
    <#if field.oldFieldName??&&field.oldFieldName!=field.fieldName>${'\t'}RENAME COLUMN `${sanitize(field.oldFieldName)}` TO `${sanitize(field.fieldName)}`,${'\n'}</#if><#t>
<#--判断新增列还是修改列-->
    ${'\t'}<#if field.oldFieldName??>MODIFY <#else >ADD </#if><#t>
     COLUMN `${sanitize(field.fieldName)}`<#t>
<#-- 修改类型 -->
    ${field.fieldType?upper_case}<#t>
<#-- 字段长度以及小数点 -->
    <#if field.fieldLength??>(${field.fieldLength?number?c}<#if field.fieldDecimal??>,${field.fieldDecimal?number?c}</#if>)</#if><#t>
<#-- 是否区分大小写 -->
    <#if collate??&&(collate=="Y" && (field.fieldType=="varchar"||field.fieldType=="char"||field.fieldType=="text"||field.fieldType=="long text"||field.fieldType=="enum"))> CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs <#elseif collate??&&(collate=="N" && (field.fieldType=="varchar"||field.fieldType=="char"||field.fieldType=="text"||field.fieldType=="long text"||field.fieldType=="enum"))> CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci </#if><#t>
<#-- 是否无符号 -->
    <#if field.unsignedFlag??&&field.unsignedFlag=="Y"> UNSIGNED </#if><#t>
<#-- 是否填充0 -->
    <#if field.fillZeroFlag??&&field.fillZeroFlag=="Y"> ZEROFILL </#if><#t>
<#-- 虚拟列类型判断 -->
    <#if field.virtualFlag??&&field.virtualFlag=="Y">
        GENERATED ALWAYS AS (${sanitize(field.virtualExpression)}) ${field.virtualType} <#t>
    </#if>
<#-- 是否允许为空 -->
    <#if (field.notNullFlag??&&field.notNullFlag=="Y") || (field.primaryFlag??&&field.primaryFlag=="Y") ||(field.autoIncrementFlag??&&field.autoIncrementFlag=="Y")> NOT NULL <#else > NULL</#if><#t>
<#-- 默认值 -->
    <#if field.defaultValue??> DEFAULT ${field.defaultValue}</#if><#t>
<#-- 是否为主键 -->
    <#if field.primaryFlag??&&field.primaryFlag=="Y"> PRIMARY KEY </#if><#t>
<#-- 是否自增 -->
    <#if field.autoIncrementFlag??&&field.autoIncrementFlag=="Y"> AUTO_INCREMENT </#if><#t>
<#-- 注释 -->
    <#if field.comment??> COMMENT '${sanitize(field.comment)}'</#if><#if field_has_next>,<#else >;<#t></#if>
</#list>
